package com.itheima.advantagesup.controller;


import com.itheima.advantagesup.common.PageBean;
import com.itheima.advantagesup.common.PaginationVO;
import com.itheima.advantagesup.common.R;
import com.itheima.advantagesup.entity.YddCate;
import com.itheima.advantagesup.service.ContentService;
import com.itheima.advantagesup.vo.cateVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/ydd_cate")
@Slf4j
public class ContentController {
    private final ContentService contentService;

    public ContentController(ContentService contentService) {
        this.contentService = contentService;
    }

    @GetMapping("/all")
    public R<List<YddCate>> getAllContent() {
        log.info("查询全部内容");
        List<YddCate> cate = contentService.getAllContent();
        return R.success(cate);
    }

    @GetMapping("/del")
    public R<?> delContent(String id) {
        log.info("删除内容{}", id);
        contentService.delContent(id);
        return R.success();
    }

    @GetMapping("/rowInfo")
    public R<cateVO> rowInfoContent(String id) {
        log.info("删除内容{}", id);
        cateVO cv = contentService.rowInfoContent(id);
        return R.success(cv);
    }

    @GetMapping("/list")
    public R<PaginationVO<cateVO>> getPageContent(String catename,
                                                  @RequestParam(defaultValue = "1") String page,
                                                  @RequestParam(defaultValue = "10") String limit) {
        log.info("分页查询全部内容:{},{},{}", catename, page, limit);
        PaginationVO<cateVO> pages = contentService.getPageContent(catename, page, limit);
        return R.success(pages);
    }

    @PostMapping("/add")
    public R<?> addContent(@RequestBody cateVO cv) {
        log.info("添加内容:{}",cv);
        contentService.addContent(cv);
        return R.success();
    }

    @PostMapping("/update")
    public R<?> updateContent(@RequestBody cateVO cv) {
        log.info("添加内容:{}", cv);
        contentService.updateContent(cv);
        return R.success();
    }
}
